Ext.define('OrderConvert.view.order.xlsGridController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.order-xlsgrid',


    preview : function (btn) {
        var grid = btn.up("grid");
        var records = grid.getSelection();
        if (records.length > 0) {
            var record = records[0];
            var fileId = record.data.sheetId;
            if (fileId) {
                window.open(OrderConvertUrl.constant.sheetServer + "view?editFileId=" + fileId);
            } else {
                Ext.Msg.alert("提示", "该订单没有转换！");
            }
        } else {
            Ext.Msg.alert("提示", "请选择订单！");
        }
    },

    delete : function (btn) {
        var grid = btn.up("grid");
        var records = grid.getSelection();
        if (records.length > 0) {
            var record = records[0];
            var id = record.data.id;
            Ext.Msg.confirm('提示', '是否确定该操作？', function (choose) {
                if(choose == "yes"){
                    Ext.Ajax.request({
                        url: OrderConvertUrl.constant.serverUrl + 'order/delete',
                        params: {
                            id: id
                        },
                        success: function (response) {
                            var text = response.responseText;
                            if (text) {
                                var json = Ext.decode(text);
                                if (json.success) {
                                    Ext.Msg.alert("提示", '操作成功！');
                                    grid.getStore().load();
                                } else {
                                    Ext.Msg.alert("提示", "操作失败！");
                                }
                            }
                        }
                    });
                }
            });
        } else {
            Ext.Msg.alert("提示", "请选择订单！");
        }
    },
    export : function (btn) {
        var grid = btn.up("grid");
        var records = grid.getSelection();
        if (records.length > 0) {
            var record = records[0];
            var fileId = record.data.isConvert;
            if (fileId) {
                var url = OrderConvertUrl.constant.sheetServer + "sheet/export?documentId=" + record.data.sheetId;
                window.open(url);
            } else {
                Ext.Msg.alert("提示", "该订单没有转换！");
            }
        } else {
            Ext.Msg.alert("提示", "请选择订单！");
        }
    }
});
